import cv2
import matplotlib.pyplot as plt

def bean_1():
    bean2 = cv2.imread('7/002.jpg', 0)
    bean2_m = cv2.equalizeHist(bean2)

    h2 = cv2.calcHist([bean2], [0], None, [256], [0, 256])
    his2 = cv2.normalize(h2, None, 1, 0, cv2.NORM_L1)

    h2_m = cv2.calcHist([bean2_m], [0], None, [256], [0, 256])
    his2_m = cv2.normalize(h2_m, None, 1, 0, cv2.NORM_L1)

    fig1 = plt.figure(figsize=(10, 8))
    
    fig1.add_subplot(2, 2, 1)
    plt.imshow(bean2, cmap='gray')
    plt.title('ori')

    fig1.add_subplot(2, 2, 2)
    plt.plot(his2)
    plt.title('ori_his')

    fig1.add_subplot(2, 2, 3)
    plt.imshow(bean2_m, cmap='gray')
    plt.title('Modi')

    fig1.add_subplot(2, 2, 4)
    plt.plot(his2_m)
    plt.title('Modi_his')

    plt.show()

def bean_2():
    bean2 = cv2.imread('7/003.jpg', 0)
    bean2_m = cv2.equalizeHist(bean2)

    h2 = cv2.calcHist([bean2], [0], None, [256], [0, 256])
    his2 = cv2.normalize(h2, None, 1, 0, cv2.NORM_L1)

    h2_m = cv2.calcHist([bean2_m], [0], None, [256], [0, 256])
    his2_m = cv2.normalize(h2_m, None, 1, 0, cv2.NORM_L1)

    fig1 = plt.figure(figsize=(10, 8))
    
    fig1.add_subplot(2, 2, 1)
    plt.imshow(bean2, cmap='gray')
    plt.title('ori')

    fig1.add_subplot(2, 2, 2)
    plt.plot(his2)
    plt.title('ori_his')

    fig1.add_subplot(2, 2, 3)
    plt.imshow(bean2_m, cmap='gray')
    plt.title('Modi')

    fig1.add_subplot(2, 2, 4)
    plt.plot(his2_m)
    plt.title('Modi_his')

    plt.show()

def bean_3():
    bean2 = cv2.imread('7/004.jpg', 0)
    bean2_m = cv2.equalizeHist(bean2)

    h2 = cv2.calcHist([bean2], [0], None, [256], [0, 256])
    his2 = cv2.normalize(h2, None, 1, 0, cv2.NORM_L1)

    h2_m = cv2.calcHist([bean2_m], [0], None, [256], [0, 256])
    his2_m = cv2.normalize(h2_m, None, 1, 0, cv2.NORM_L1)

    fig1 = plt.figure(figsize=(10, 8))
    
    fig1.add_subplot(2, 2, 1)
    plt.imshow(bean2, cmap='gray')
    plt.title('ori')

    fig1.add_subplot(2, 2, 2)
    plt.plot(his2)
    plt.title('ori_his')

    fig1.add_subplot(2, 2, 3)
    plt.imshow(bean2_m, cmap='gray')
    plt.title('Modi')

    fig1.add_subplot(2, 2, 4)
    plt.plot(his2_m)
    plt.title('Modi_his')

    plt.show()

def main():
    bean_1()
    bean_2()
    bean_3()

if __name__ == '__main__':
    main()